package com.epam.run;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;

public class FileLoader {

	public static String readFile(String path, Charset encoding)
			throws IOException {
		byte[] encoded = Files.readAllBytes(Paths.get(path));
		return encoding.decode(ByteBuffer.wrap(encoded)).toString();
	}
	
	public static String readLines(String path, Charset encoding) 
			throws IOException {
		List<String> list = Files.readAllLines(Paths.get(path), encoding);
		String res="";
		for (String temp:list) {
			res+=temp.replaceAll("\\p{Blank}{2,}", " ");
		}
		return res;
	}
}
